import 'package:flutter/material.dart';
import 'package:woandroid/pages/BaseState.dart';
import 'package:woandroid/pages/SearchResultPage.dart';
import 'package:woandroid/pages/HotSearchPage.dart';

class SearchPage extends StatefulWidget{
  String searchStr;
  SearchPage(this.searchStr);


  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new SearchPageState();
  }
}
class SearchPageState extends BaseState<SearchPage>{
  TextEditingController controller;
  SearchResultPage searchResultPage;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    controller=new TextEditingController(text: widget.searchStr,);
    changeContent();
  }

  @override
  Widget build(BuildContext context) {

    TextField searchField=new TextField(
      autofocus: true,
      style: TextStyle(color: Colors.white,fontSize: 16),
      cursorColor: Colors.deepPurple,
      decoration: new InputDecoration(
        border: InputBorder.none,
        hintText: '输入关键字搜索',
        hintStyle: TextStyle(color: Colors.deepPurple)
      ),
      controller: controller,
    );


    return Scaffold(

      appBar: AppBar(title: searchField,

         actions: <Widget>[
           IconButton(icon: Icon(Icons.search,color: Colors.white,),
           onPressed: (){
             changeContent();
           },
           ),
          IconButton(icon: Icon(Icons.clear,color:Colors.white,),
          onPressed: (){
            controller.clear();
          },
          )
         ],
      ),

      body: (controller.text==null||controller.text.isEmpty)?HotSearchPage():searchResultPage,
    );

    // TODO: implement build
  }

  void changeContent() {
     setState(() {
       searchResultPage=new SearchResultPage(ValueKey(controller.text));
     });
  }
}